package com.wgts.wgts.mvp.view.activity.guessing;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wgts.wgts.R;
import com.wgts.wgts.control.recycleview.BaseLoadMoreAdapter;
import com.wgts.wgts.netmodle.resp.AwardPrizeEntity;
import com.wgts.wgts.tools.MoHuGlide;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/*
 *
 *
 *   data:2018/10/1221:18
 *
 *   奖品recycleView 子Adapter
 *
 */public class GuessingAwardAdapter extends BaseLoadMoreAdapter<GuessingAwardAdapter.ViewHold> {
    private Context context;
    private List<AwardPrizeEntity> list;

    private OnClickListener onClickListener;

    public GuessingAwardAdapter(Context context, List<AwardPrizeEntity> list) {
        super(context);
        this.context = context;
        this.list = list;
    }

    @Override
    public void onBindBodyViewHolder(@NonNull ViewHold viewHolder, final int i) {

        if(list.get(i).drawOrderCode != null){
            viewHolder.orderNumber.setText(list.get(i).drawOrderCode);
        }

        MoHuGlide.getInstance().glideImgsFormList(viewHolder.goodsImage, list.get(i).productSmallImage, context);
        viewHolder.goodsName.setText(list.get(i).productName);
        viewHolder.goodsPrice.setText(list.get(i).productPrice);
        viewHolder.orderTime.setText(list.get(i).winnerTime);
        //viewHolder.orderNumber.setText(list.get(i).shareCode);

        switch (list.get(i).status){
            case "1":
                viewHolder.tvStatue.setText("待开奖");
                viewHolder.itemView.setEnabled(false);
                viewHolder.orderButtonLy.setVisibility(View.INVISIBLE);
                break;
            case "2":
                viewHolder.tvStatue.setText("未中奖");
                viewHolder.itemView.setEnabled(false);
                viewHolder.orderButtonLy.setVisibility(View.INVISIBLE);
                break;
            case "3":
                viewHolder.tvStatue.setText("未领取");
                viewHolder.itemView.setEnabled(true);
                viewHolder.orderButtonText.setVisibility(View.VISIBLE);
                viewHolder.orderButtonText.setText("立即领取");
                break;
            case "4":
                if(list.get(i).expressStatus == 0){
                    viewHolder.tvStatue.setText("待发货");
                    viewHolder.itemView.setEnabled(true);
                    viewHolder.orderButtonLy.setVisibility(View.VISIBLE);
                    viewHolder.orderButtonText.setText("待发货");
                }else{
                    viewHolder.tvStatue.setText("确认收货");
                    viewHolder.itemView.setEnabled(true);
                    viewHolder.orderButtonLy.setVisibility(View.VISIBLE);
                    viewHolder.orderButtonText.setText("确认收货");
                }
                break;
            case "5":
                viewHolder.tvStatue.setText("已完成");
                viewHolder.itemView.setEnabled(true);
                viewHolder.orderButtonLy.setVisibility(View.INVISIBLE);
                break;
            case "6":
                viewHolder.tvStatue.setText("已失效");
                viewHolder.itemView.setEnabled(false);
                viewHolder.orderButtonLy.setVisibility(View.INVISIBLE);
                break;
        }

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(onClickListener != null){
                    onClickListener.onClick(v, i);
                }
            }
        });
    }

    @NonNull
    @Override
    public ViewHold onCreateBodyViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new ViewHold(LayoutInflater.from(context).inflate(R.layout.guessing_award_child_item, viewGroup, false));
    }


    @Override
    public int getBodyItemCount() {
        return list.size();
    }

    @Override
    public int getBodyItemViewType(int position) {
        return 0;
    }

    public class ViewHold extends RecyclerView.ViewHolder {
        @BindView(R.id.order_number)
        TextView orderNumber;
        @BindView(R.id.goods_image)
        ImageView goodsImage;
        @BindView(R.id.goods_name)
        TextView goodsName;
        @BindView(R.id.place_holder_view)
        TextView placeHolderView;
        @BindView(R.id.goods_price)
        TextView goodsPrice;
        @BindView(R.id.order_day)
        TextView orderDay;
        @BindView(R.id.order_time)
        TextView orderTime;
        @BindView(R.id.order_button_text)
        TextView orderButtonText;
        @BindView(R.id.order_button_ly)
        RelativeLayout orderButtonLy;
        @BindView(R.id.tv_statue)
        TextView tvStatue;

        public View itemView;

        public ViewHold(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            this.itemView = itemView;
        }
    }

    public interface OnClickListener{
        void onClick(View view, int i);
    }


    public void setOnClickListener(OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }
}
